package misc;

import nl.preflag.basewars.R;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.content.Context;

/**
 * @author Glenn Vlekke, 0805372 MT4A
 * Menu that can be implemented in other activitys
 *  
 */

@SuppressWarnings("unused")
public class MainMenu {
	
	/**
	 * On create options menu
	 * 
	 * @param activity
	 * @param menu
	 * @return boolean, for now it always returns true
	 */
	public static boolean onCreateOptionsMenu(Activity activity, Menu menu)
	{
		// get the menu inflater
		MenuInflater inflater = activity.getMenuInflater();
				
		// inflate the menu layout
		inflater.inflate(R.menu.main_menu, menu);
		
		// TODO maybe have some error handeling over here?
		return true;
	}

	/**
	 * On options item selected
	 * 
	 * @param activity The activity where the button was pressed
	 * @param item The button that was pressed
	 * @return boolean 
	 * 		true = find a item in menu
	 * 		false = did not find any item in the menu
	 */
	public static boolean onOptionsItemSelected(Activity activity, MenuItem item) 
	{
		// check the button
		switch( item.getItemId() )
		{
			case R.id.logout:
				activity.getSharedPreferences("programSettings", Activity.MODE_PRIVATE)
		        .edit()
		        .putString("userId", "")
		        .commit();	
				return true;
		}
		return false;
	}
}
